package com.zhangh.summer.admin.biz.menu.impl;

import com.zhangh.summer.admin.model.bo.MenuBO;
import com.zhangh.summer.admin.model.bo.MenuQuery;
import com.zhangh.summer.admin.model.enums.MenuTypeEnum;
import com.zhangh.summer.admin.model.po.*;
import com.zhangh.summer.admin.support.aop.tx.MultiDs;
import com.zhangh.summer.admin.support.ds.common.MixedDS;
import com.zhangh.summer.admin.support.exception.BizException;
import com.zhangh.summer.admin.support.id.IdGen;
import com.zhangh.summer.admin.support.utils.BeanGenerator;
import com.zhangh.summer.admin.biz.menu.MenuBiz;
import com.zhangh.summer.admin.biz.menu.OperationBiz;
import com.zhangh.summer.admin.model.bo.OperationBO;

import com.zhangh.summer.admin.support.session.SysSession;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @description: TODO
 * @author: zhanghui  zhanghlucky@163.com
 * @create: 2021-09-28 01:31
 **/
@Service
@Slf4j
public class MenuBizImpl implements MenuBiz {
    @Resource
    private MixedDS mixedDS;
    @Autowired
    private IdGen idGen;
    @Autowired
    private OperationBiz operationBiz;

    @Override
    @MultiDs
    public List<MenuBO> getMenuList(MenuQuery query) {
        /*AdMenuPOExample menuPOExample=new AdMenuPOExample();
        AdMenuPOExample.Criteria c=menuPOExample.createCriteria();
        if (StringUtils.isNotBlank(query.getMenuName())){
            c.andMenuNameLike("%"+query.getMenuName()+"%");
        }
        menuPOExample.setOrderByClause("priority asc ");
        List<AdMenuPO> menuPOList=this.mixedDS.txDs().mapper().selectByExample(menuPOExample);*/
        Map<String,Object> params=new HashMap<>();
        if (StringUtils.isNotBlank(query.getMenuName())){
            params.put("menuName",query.getMenuName());
        }
        List<MenuBO> menuBOList=this.mixedDS.txDs().mapper("MenuMapper").selectList("selectMenuBOList",params);

        List<MenuBO> treeMenuBOList=menuBOList;
        //补父节点
        if (StringUtils.isNotBlank(query.getMenuName())){
            params.clear();
            List<MenuBO> allMenuBOList=this.mixedDS.txDs().mapper("MenuMapper").selectList("selectMenuBOList",params);
            List<Long> ids=new ArrayList<>();
            for (MenuBO menuBO : menuBOList) {
                List<Long> itemParentIDS=this.getMenuBOParents(menuBO,allMenuBOList);
                ids.addAll(itemParentIDS);
            }
            List<Long> menuIDS=menuBOList.stream().map(MenuBO::getId).collect(Collectors.toList());
            ids.addAll(menuIDS);//聚合所有ID
            List<Long> treeMenuIDS = ids.stream().distinct().collect(Collectors.toList());//去重
            treeMenuBOList=allMenuBOList.stream().filter(item-> treeMenuIDS.contains(item.getId())).collect(Collectors.toList());
        }

        AdOperationPOExample operationPOExample=new AdOperationPOExample();
        List<AdOperationPO> operationPOList=this.mixedDS.txDs().mapper().selectByExample(operationPOExample);
        //构建树结构
        List<MenuBO> list=getMenuBOTreeList(treeMenuBOList,operationPOList,null,null);
        return list;
    }

    private List<Long> getParents(AdMenuPO menuPO,List<AdMenuPO> allMenuPOList){
        List<Long> list=new ArrayList<>();
        for (AdMenuPO adMenuPO : allMenuPOList) {
            if (menuPO.getPid()!=0&&menuPO.getPid().equals(adMenuPO.getId())){
                list.add(adMenuPO.getId());
                List<Long> childList=getParents(adMenuPO,allMenuPOList);
                list.addAll(childList);
            }
        }
        return list;
    }

    private List<Long> getMenuBOParents(MenuBO menuPO,List<MenuBO> allMenuPOList){
        List<Long> list=new ArrayList<>();
        for (MenuBO itemBO : allMenuPOList) {
            if (menuPO.getPid()!=0&&menuPO.getPid().equals(itemBO.getId())){
                list.add(itemBO.getId());
                List<Long> childList=getMenuBOParents(itemBO,allMenuPOList);
                list.addAll(childList);
            }
        }
        return list;
    }

    public List<MenuBO> getMenuBOTreeList(List<MenuBO> menuList,List<AdOperationPO> operationPOList,
                                        List<Long> checkedMenuIDList,List<Long> checkedOperationIDList){
        //root
        List<MenuBO> rootList=menuList.stream().filter(item->item.getPid()==0).collect(Collectors.toList());
        //构建树结构
        List<MenuBO> menuBOList=new ArrayList<>();
        for (AdMenuPO menuPO : rootList) {
            MenuBO menuBO=this.buildMenuBO(menuPO,menuList,operationPOList,checkedMenuIDList,checkedOperationIDList);
            if (null!=checkedMenuIDList){
                boolean isChecked=checkedMenuIDList.stream().anyMatch(item->item.equals(menuBO.getId()));
                menuBO.setChecked(isChecked);
            }
            if (null!=operationPOList){
                List<AdOperationPO> originalOperations=operationPOList.stream().filter(item->item.getMenuID().equals(menuPO.getId())).collect(Collectors.toList());
                List<OperationBO> operations=originalOperations.stream().map(optPO->{
                    OperationBO operationBO= BeanGenerator.copy(optPO,OperationBO.class);
                    if (null!=checkedOperationIDList){
                        boolean isChecked=checkedOperationIDList.stream().anyMatch(checkedOptID->checkedOptID.equals(optPO.getId()));
                        operationBO.setChecked(isChecked);
                    }
                    return operationBO;
                }).collect(Collectors.toList());
                menuBO.setOperations(operations);
            }
            String fullUrl=menuBO.getMenuUrl();
            if (StringUtils.isNotBlank(menuBO.getSysCode())){
                fullUrl="/"+menuBO.getSysCode()+menuBO.getMenuUrl();
            }
            menuBO.setFullUrl(fullUrl);
            menuBOList.add(menuBO);
        }
        return menuBOList;
    }


    public List<MenuBO> getMenuTreeList(List<AdMenuPO> menuPOList,List<AdOperationPO> operationPOList,
                                         List<Long> checkedMenuIDList,List<Long> checkedOperationIDList){
        //root
        List<AdMenuPO> rootList=menuPOList.stream().filter(item->item.getPid()==0).collect(Collectors.toList());
        //构建树结构
        List<MenuBO> menuBOList=new ArrayList<>();
        for (AdMenuPO menuPO : rootList) {
            MenuBO menuBO=this.buildMenu(menuPO,menuPOList,operationPOList,checkedMenuIDList,checkedOperationIDList);
            /*if (null!=checkedMenuIDList){
                boolean isChecked=checkedMenuIDList.stream().anyMatch(item->item.equals(menuBO.getId()));
                menuBO.setChecked(isChecked);
            }
            if (null!=operationPOList){
                List<AdOperationPO> originalOperations=operationPOList.stream().filter(item->item.getMenuID().equals(menuPO.getId())).collect(Collectors.toList());
                List<OperationBO> operations=originalOperations.stream().map(optPO->{
                    OperationBO operationBO= BeanGenerator.copy(optPO,OperationBO.class);
                    if (null!=checkedOperationIDList){
                        boolean isChecked=checkedOperationIDList.stream().anyMatch(checkedOptID->checkedOptID.equals(optPO.getId()));
                        operationBO.setChecked(isChecked);
                    }
                    return operationBO;
                }).collect(Collectors.toList());
                menuBO.setOperations(operations);
            }
            String fullUrl=menuBO.getMenuUrl();
            if (StringUtils.isNotBlank(menuBO.getSysCode())){
                fullUrl="/"+menuBO.getSysCode()+menuBO.getMenuUrl();
            }
            menuBO.setFullUrl(fullUrl);*/
            menuBOList.add(menuBO);
        }
        return menuBOList;
    }

    @Override
    public MenuBO getHomeMenu() {
        Map<String,Object> params=new HashMap<>();
        params.put("menuType",MenuTypeEnum.HOME.getValue());
        MenuBO menuBO =this.mixedDS.txDs().mapper("MenuMapper").selectOne("selectMenuBOList",params);
        String fullUrl=menuBO.getMenuUrl();
        if (StringUtils.isNotBlank(menuBO.getSysCode())){
            fullUrl="/"+menuBO.getSysCode()+menuBO.getMenuUrl();
        }
        menuBO.setFullUrl(fullUrl);
        return menuBO;
    }

    @Override
    @Transactional
    public int setHome(Long id) {
        AdMenuPOExample example=new AdMenuPOExample();
        example.createCriteria().andMenuTypeNotEqualTo(MenuTypeEnum.NORMAL.getValue());

        AdMenuPO adMenuPO=new AdMenuPO();
        adMenuPO.setUpdateBy(SysSession.getUser().getLoginName());
        adMenuPO.setUpdateTime(new Date());
        adMenuPO.setMenuType(MenuTypeEnum.NORMAL.getValue());
        int c1=this.mixedDS.txDs().mapper().updateByExampleSelective(adMenuPO,example);

        adMenuPO.setId(id);
        adMenuPO.setMenuType(MenuTypeEnum.HOME.getValue());
        int c2=this.mixedDS.txDs().mapper().updateByPrimaryKeySelective(adMenuPO);
        log.info("设置 id {} 的菜单为首页",id);

        return c2;
    }

    private MenuBO buildMenuBO(AdMenuPO root,List<MenuBO> menuList,List<AdOperationPO> operationPOList,
                             List<Long> checkedMenuIDList,List<Long> checkedOperationIDList){
        MenuBO menuBO= BeanGenerator.copy(root,MenuBO.class);
        List<MenuBO> childPOList=menuList.stream().filter(item-> item.getPid().equals(root.getId())).collect(Collectors.toList());
        List<MenuBO> children=new ArrayList<>();
        for (AdMenuPO childPO : childPOList) {
            MenuBO childBO=this.buildMenuBO(childPO,menuList,operationPOList,checkedMenuIDList,checkedOperationIDList);
            children.add(childBO);
        }
        if (null!=checkedMenuIDList){
            boolean isChecked=checkedMenuIDList.stream().anyMatch(item->item.equals(menuBO.getId()));
            menuBO.setChecked(isChecked);
        }
        menuBO.setChildren(children.size()>0?children:null);

        List<AdOperationPO> originalOperations=operationPOList.stream().filter(item->item.getMenuID().equals(root.getId())).collect(Collectors.toList());
        List<OperationBO> operations=originalOperations.stream().map(optPO->{
            OperationBO operationBO=BeanGenerator.copy(optPO,OperationBO.class);
            if (null!=checkedOperationIDList){
                boolean isChecked=checkedOperationIDList.stream().anyMatch(checkedOptID->checkedOptID.equals(optPO.getId()));
                operationBO.setChecked(isChecked);
            }
            return operationBO;
        }).collect(Collectors.toList());

        String fullUrl=menuBO.getMenuUrl();
        if (StringUtils.isNotBlank(menuBO.getSysCode())){
            fullUrl="/"+menuBO.getSysCode()+menuBO.getMenuUrl();
        }
        menuBO.setFullUrl(fullUrl);
        menuBO.setOperations(operations);
        return menuBO;
    }


    private MenuBO buildMenu(AdMenuPO root,List<AdMenuPO> menuPOList,List<AdOperationPO> operationPOList,
                             List<Long> checkedMenuIDList,List<Long> checkedOperationIDList){
        MenuBO menuBO= BeanGenerator.copy(root,MenuBO.class);
        List<AdMenuPO> childPOList=menuPOList.stream().filter(item-> item.getPid().equals(root.getId())).collect(Collectors.toList());
        List<MenuBO> children=new ArrayList<>();
        for (AdMenuPO childPO : childPOList) {
            MenuBO childBO=this.buildMenu(childPO,menuPOList,operationPOList,checkedMenuIDList,checkedOperationIDList);
            children.add(childBO);
        }
        if (null!=checkedMenuIDList){
            boolean isChecked=checkedMenuIDList.stream().anyMatch(item->item.equals(menuBO.getId()));
            menuBO.setChecked(isChecked);
        }
        menuBO.setChildren(children.size()>0?children:null);

        List<AdOperationPO> originalOperations=operationPOList.stream().filter(item->item.getMenuID().equals(root.getId())).collect(Collectors.toList());
        List<OperationBO> operations=originalOperations.stream().map(optPO->{
            OperationBO operationBO=BeanGenerator.copy(optPO,OperationBO.class);
            if (null!=checkedOperationIDList){
                boolean isChecked=checkedOperationIDList.stream().anyMatch(checkedOptID->checkedOptID.equals(optPO.getId()));
                operationBO.setChecked(isChecked);
            }
            return operationBO;
        }).collect(Collectors.toList());

        String fullUrl=menuBO.getMenuUrl();
        if (StringUtils.isNotBlank(menuBO.getSysCode())){
            fullUrl="/"+menuBO.getSysCode()+menuBO.getMenuUrl();
        }
        menuBO.setFullUrl(fullUrl);
        menuBO.setOperations(operations);
        return menuBO;
    }

    @Override
    @MultiDs
    public MenuBO getMenuBO(Long id) {
        AdMenuPO menuPO=this.mixedDS.txDs().mapper().selectByPrimaryKey(AdMenuPO.class,id);
        AdOperationPOExample operationPOExample=new AdOperationPOExample();
        operationPOExample.createCriteria().andMenuIDEqualTo(id);
        List<AdOperationPO> originalOperations=this.mixedDS.txDs().mapper().selectByExample(operationPOExample);
        List<OperationBO> operations=originalOperations.stream().map(item->{
            OperationBO operationBO=BeanGenerator.copy(item,OperationBO.class);
            return operationBO;
        }).collect(Collectors.toList());

        MenuBO menuBO=BeanGenerator.copy(menuPO,MenuBO.class);
        menuBO.setOperations(operations);

        return menuBO;
    }

    @Override
    @MultiDs
    @Transactional
    public Long saveMenu(MenuBO menuBO) {
        AdMenuPO adMenuPO=BeanGenerator.copy(menuBO,AdMenuPO.class);
        adMenuPO.setId(idGen.getID());
        if (menuBO.isOnRoot()){
            adMenuPO.setPid(0L);
            adMenuPO.setLevel(0);
        }else{
            MenuBO parent=this.getMenuBO(adMenuPO.getPid());
            adMenuPO.setLevel(parent.getLevel()+1);
        }
        double priority=this.getNewPriority(adMenuPO.getPid());
        adMenuPO.setPriority(priority);
        adMenuPO.setCreateBy(SysSession.getUser().getLoginName());
        adMenuPO.setCreateTime(new Date());
        adMenuPO.setUpdateBy(SysSession.getUser().getLoginName());
        adMenuPO.setUpdateTime(new Date());
        this.mixedDS.txDs().mapper().insert(adMenuPO);
        log.info("保存菜单 id {}",adMenuPO.getId());
        List<OperationBO> operationBOS=menuBO.getOperations();
        List<AdOperationPO> operationPOS=operationBOS.stream().map(item->{
            AdOperationPO adOperationPO=BeanGenerator.copy(item,AdOperationPO.class);
            return adOperationPO;
        }).collect(Collectors.toList());
        operationPOS.stream().forEach(operationPO->{
            operationPO.setId(idGen.getID());
            operationPO.setMenuID(adMenuPO.getId());
            operationPO.setIsEnable(true);
            operationPO.setCreateBy(SysSession.getUser().getLoginName());
            operationPO.setCreateTime(new Date());
            operationPO.setUpdateBy(SysSession.getUser().getLoginName());
            operationPO.setUpdateTime(new Date());
        });
        if (operationPOS.size()>0){
            int c1=this.mixedDS.txDs().mapper().batchInsert(operationPOS,AdOperationPO.class);
            log.info("保存操作 size {}",c1);
        }
        return adMenuPO.getId();
    }

    private double getNewPriority(long pid){
        AdMenuPOExample example=new AdMenuPOExample();
        example.createCriteria().andPidEqualTo(pid);
        example.setOrderByClause("priority desc");
        AdMenuPO menuPO=this.mixedDS.txDs().mapper().selectFirstByExample(example);
        double priority=0.0;
        if (null!=menuPO){
            priority=menuPO.getPriority()+1;
        }
        return priority;
    }

    @Override
    @MultiDs
    @Transactional
    public int updateMenu(MenuBO menuBO) {
        AdMenuPO adMenuPO=BeanGenerator.copy(menuBO,AdMenuPO.class);
        adMenuPO.setUpdateBy(SysSession.getUser().getLoginName());
        adMenuPO.setUpdateTime(new Date());
        int c1=this.mixedDS.txDs().mapper().updateByPrimaryKey(adMenuPO);
        log.info("更新菜单 {}",menuBO.getId());
        if (!adMenuPO.getIsEnable()){//禁用菜单，递归禁用子节点
            this.setMenuDisable(adMenuPO.getId());
        }

        AdOperationPOExample operationPOExample=new AdOperationPOExample();
        operationPOExample.createCriteria().andMenuIDEqualTo(menuBO.getId());
        List<AdOperationPO> originalOperationList=this.mixedDS.txDs().mapper().selectByExample(operationPOExample);
        List<OperationBO> operationBOS=menuBO.getOperations();
        List<AdOperationPO> operationPOS=operationBOS.stream().map(item->{
            AdOperationPO adOperationPO=BeanGenerator.copy(item,AdOperationPO.class);
            return adOperationPO;
        }).collect(Collectors.toList());

        List<Long> deleteIDList=originalOperationList.stream().map(AdOperationPO::getId).collect(Collectors.toList())
                .stream().filter(id->!operationPOS.stream().map(AdOperationPO::getId).collect(Collectors.toList())
                        .contains(id))
                .collect(Collectors.toList());
        List<AdOperationPO> updateList=operationPOS.stream().filter(item->item.getId()!=0).collect(Collectors.toList());
        List<AdOperationPO> insertList=operationPOS.stream().filter(item->item.getId()==0).collect(Collectors.toList());
        for (AdOperationPO adOperationPO : updateList) {
            this.mixedDS.txDs().mapper().updateByPrimaryKey(adOperationPO);
        }
        log.info("更新操作 size {}",updateList.size());
        if (insertList.size()>0){
            insertList.stream().forEach(operationPO->{
                operationPO.setId(idGen.getID());
                operationPO.setMenuID(adMenuPO.getId());
                operationPO.setIsEnable(true);
                operationPO.setCreateBy(SysSession.getUser().getLoginName());
                operationPO.setCreateTime(new Date());
                operationPO.setUpdateBy(SysSession.getUser().getLoginName());
                operationPO.setUpdateTime(new Date());
            });
            this.mixedDS.txDs().mapper().batchInsert(insertList,AdOperationPO.class);
            log.info("插入操作 size {}",insertList.size());
        }
        if (deleteIDList.size()>0){
            operationPOExample.clear();
            operationPOExample.createCriteria().andIdIn(deleteIDList);
            int c3=this.mixedDS.txDs().mapper().deleteByExample(operationPOExample);
            log.info("删除操作 size {}",c3);
        }
        return c1;
    }
    private void setMenuDisable(Long pid){
        AdMenuPOExample example=new AdMenuPOExample();
        example.createCriteria().andPidEqualTo(pid);
        List<AdMenuPO> menuPOList=this.mixedDS.txDs().mapper().selectByExample(example);
        for (AdMenuPO adMenuPO : menuPOList) {
            adMenuPO.setIsEnable(false);
            this.mixedDS.txDs().mapper().updateByPrimaryKey(adMenuPO);
            log.info("更新菜单 name {} isEnable=false",adMenuPO.getMenuName());
            this.setMenuDisable(adMenuPO.getId());
        }
    }

    @Override
    @MultiDs
    @Transactional
    public int deleteMenu(Long id) {
        AdAuthRelationPOExample relationPOExample=new AdAuthRelationPOExample();
        relationPOExample.createCriteria().andMenuIDEqualTo(id);
        long c1=this.mixedDS.txDs().mapper().countByExample(relationPOExample);
        if (c1>0){
            log.error("菜单 id {}已经被权限使用，不能删除！",id);
            throw BizException.exception("菜单 id {0}已经被权限使用，不能删除！",id);
        }
        AdMenuPOExample menuPOExample=new AdMenuPOExample();
        menuPOExample.createCriteria().andPidEqualTo(id);
        List<AdMenuPO> children=this.mixedDS.txDs().mapper().selectByExample(menuPOExample);
        for (AdMenuPO child : children) {
            this.deleteMenu(child.getId());//递归删除
        }

        List<AdOperationPO> operationPOS=this.operationBiz.getMenuOperation(id);
        if (operationPOS.size()>0){
            relationPOExample.clear();
            relationPOExample.createCriteria().andOptIDIn(operationPOS.stream().map(AdOperationPO::getId).collect(Collectors.toList()));
            //删除操作权限关系
            int c2=this.mixedDS.txDs().mapper().deleteByExample(relationPOExample);
            log.info("删除权限操作关系 size {}",c2);
            //删除操作
            AdOperationPOExample operationPOExample=new AdOperationPOExample();
            operationPOExample.createCriteria().andMenuIDEqualTo(id);
            int c3=this.mixedDS.txDs().mapper().deleteByExample(operationPOExample);
            log.info("删除操作 size {}",c3);
        }

        //删除菜单
        int c4=this.mixedDS.txDs().mapper().deleteByPrimaryKey(AdMenuPO.class,id);
        log.info("删除菜单 id {}",id);

        return c4;
    }

    @Override
    @MultiDs
    @Transactional
    public void menuSort(List<MenuBO> menuBOList) {
        if (null!=menuBOList){
            for (int i = 0; i < menuBOList.size(); i++) {
                MenuBO menuBO=menuBOList.get(i);
                AdMenuPO adMenuPO=new AdMenuPO();
                adMenuPO.setId(menuBO.getId());
                adMenuPO.setPriority((double)i);
                this.mixedDS.txDs().mapper().updateByPrimaryKeySelective(adMenuPO);
                if (null!=menuBO.getChildren()&&menuBO.getChildren().size()>0){
                    this.menuSort(menuBO.getChildren());
                }
            }
            log.info("菜单排序 size :{}",menuBOList.size());
        }
    }

    @Override
    public List<MenuBO> getAuthMenuList(Long authID) {
        Map<String,Object> params=new HashMap<>();
        params.put("authID",authID);
        List<AdMenuPO> menuPOList=this.mixedDS.txDs().mapper("AuthMapper")
                .selectList("selectAuthMenu",params);

        List<AdOperationPO> operationPOList=this.mixedDS.txDs().mapper("AuthMapper")
                .selectList("selectAuthOperation",params);

        List<MenuBO> menuBOList=getMenuTreeList(menuPOList,operationPOList,null,null);
        return menuBOList;
    }

    @Override
    public List<MenuBO> getUserAuthMenuList(Long userID) {
        Map<String,Object> params=new HashMap<>();
        params.put("userID",userID);
        List<MenuBO> menuBOList=this.mixedDS.txDs().mapper("AuthMapper")
                .selectList("selectUserAuthMenuBO",params);

        List<AdOperationPO> operationPOList=this.mixedDS.txDs().mapper("AuthMapper")
                .selectList("selectUserAuthOperation",params);

        List<MenuBO> list=getMenuBOTreeList(menuBOList,operationPOList,null,null);
        return list;
    }

    @Override
    public List<MenuBO> getAuthMenuListForCheck(Long authID) {
        AdMenuPOExample menuPOExample=new AdMenuPOExample();
        menuPOExample.createCriteria().andIsEnableEqualTo(true);//可用的菜单
        menuPOExample.setOrderByClause("priority asc ");
        List<AdMenuPO> menuPOList=this.mixedDS.txDs().mapper().selectByExample(menuPOExample);

        AdOperationPOExample operationPOExample=new AdOperationPOExample();
        List<AdOperationPO> operationPOList=this.mixedDS.txDs().mapper().selectByExample(operationPOExample);

        if (authID!=0){
            Map<String,Object> params=new HashMap<>();
            params.put("authID",authID);
            List<AdMenuPO> checkedMenuPOList=this.mixedDS.txDs().mapper("AuthMapper")
                    .selectList("selectAuthMenu",params);
            List<Long> checkedMenuList=checkedMenuPOList.stream().map(AdMenuPO::getId).collect(Collectors.toList());

            List<AdOperationPO> checkedOperationPOList=this.mixedDS.txDs().mapper("AuthMapper")
                    .selectList("selectAuthOperation",params);
            List<Long> checkedOperationList=checkedOperationPOList.stream().map(AdOperationPO::getId).collect(Collectors.toList());
            //构建树结构
            List<MenuBO> menuBOList=getMenuTreeList(menuPOList,operationPOList,checkedMenuList,checkedOperationList);
            return menuBOList;
        }else{
            List<MenuBO> menuBOList=getMenuTreeList(menuPOList,operationPOList,null,null);
            return menuBOList;
        }

    }

}
